const app = getApp();
const { getUserInfo, getUserInfoWidthCredentials } = require('../../../common/utils/ws/wsxcx-opendata-sdk');
Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    isAnchor: null,
  },
  onLoad(options) {
    this.checkUserInfo();
    this.setData({
      isAnchor: Number(JSON.parse(options.isAnchor)),
    });
  },
  getUserInfoWidthCredentials(e) {
    getUserInfoWidthCredentials({
      url: 'auth/session/userinfo',
      method: 'POST',
      detail: e.detail,
      cachetime: 0,
    }).then(res => {
      getUserInfo().then(res => {
        this.setData({
          userInfo: wx.getStorageSync('wsUserInfo'),
          hasUserInfo: true,
        });
      });
    });
  },
  checkUserInfo() {
    getUserInfo().then(res => {
      this.setData({
        userInfo: wx.getStorageSync('wsUserInfo'),
        hasUserInfo: true,
      });
    }).catch(res => {
      this.setData({
        hasUserInfo: false,
      });
    });
  },
  toStudio(){
    let { hasUserInfo,userInfo } = this.data;
    if(!hasUserInfo){
      wx.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 2000,
      });
      return;
    }
    app.util.navigateTo(`/cm_lvb/pages/studio/studio?userInfo=${JSON.stringify(userInfo)}`);
  },
});

